<?php
namespace app\admin\controller;
use think\Controller;
use think\Verify;
use think\Db;
use think\Request;
use think\Captcha;
use think\Session;
class Login extends Controller
{
    public function index()
    {                       
        return $this->fetch('index/login');
    }
    public function check(Request $request){
        $username=$request->param('username');
        $userpass=$request->param('pass');
        $status=$request->param('status');
        $code = $request->param('code');
        $captcha = new \think\captcha\Captcha();
        if (!$captcha->check($code)) {
            $this->error('验证码错误');
        } else {
            // $this->success('验证码正确','index');
            $userData=Db::table('admin')->where('username',$username)->find();
            if($userData){
                if($userData['password']==md5($userpass)){
                    Session::set('id',$userData['id']);
                    Session::set('name',$userData['username']);
                    $this->success('登录成功','admin/index');
                }else{
                   $this->error('密码错误,请检查输入'); 
                }
            }else{
                $this->error('用户不存在,请检查输入');
            }
        }    
    }
    /*
    *退出登录
    */
    public function logout(){
        // 清除登陆信息
        Session::clear();
        $this->success('退出成功','index');        
    }
}
